<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 	
	xmlns:v="urn:schemas-microsoft-com:vml"	>
	<xsl:output method="html"  version="1.0" encoding="gb2312"/>
	
	<xsl:template match="/Process">
		<xsl:element name="table">
			<xsl:attribute name="style">position:absolute;top:<xsl:call-template name="GetMaxTop" />px;</xsl:attribute>
			<tr> 
			<td colspan="10" height="50px">
				<xsl:call-template name="CreateLine" />  
			</td>
			</tr>
			<tr VALIGN="top">
				<xsl:call-template name="Steps" />
			</tr>
		</xsl:element>
	</xsl:template>

	<xsl:template name="Steps">
		<xsl:for-each select="/Process/Steps/Step">
			<td >
			    <xsl:call-template name="CreateGraph" >
				</xsl:call-template>
			</td>
			<xsl:if test="not(position()=last())">
				<td ><xsl:call-template name="CreateArrow" /></td>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>


	<xsl:template name="GetMaxTop">
		<xsl:for-each select="//NextStepID/../../../Attributes/StepID">
			<xsl:sort data-type="number" order="descending" />
			<xsl:if test="position(  ) = 1">
				<xsl:value-of select="number(.) * 10" />
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="CreateGraph">
		<xsl:element name="div">
			<xsl:attribute name="id">dv_<xsl:value-of select="./Attributes/StepID" /></xsl:attribute>
			<xsl:attribute name="stepid"><xsl:value-of select="./Attributes/StepID" /></xsl:attribute>
			<xsl:attribute name="stepguid"><xsl:value-of select="./Attributes/StepGUID" /></xsl:attribute>
			<xsl:attribute name="processguid"><xsl:value-of select="/Process/Attributes/ProcessGUID" /></xsl:attribute>
			<xsl:attribute name="businesstypeguid"><xsl:value-of select="/Process/Attributes/BusinessTypeGUID" /></xsl:attribute>
			<xsl:attribute name="style">width:150px;height:100%;padding-left:1px;padding-top:1px</xsl:attribute>
			<xsl:attribute name="onclick">selectStep(this);showMenu();</xsl:attribute>
			<!--xsl:attribute name="ondblclick">openStep()</xsl:attribute-->
			<!--xsl:attribute name="oncontextmenu">showMenu();</xsl:attribute-->

			<xsl:element name="v:roundrect" use-attribute-sets="steprect">
				<xsl:choose>
					<xsl:when test="./Attributes/StepStatus = 1 or ./Attributes/StepStatus = 2 ">
						<xsl:attribute name="fillcolor">#F79A01</xsl:attribute>
					</xsl:when>
					<xsl:when test="./Attributes/StepStatus = 3 or  ./Attributes/StepStatus = -3 or ./Attributes/StepStatus = -2 or ./Attributes/StepStatus = -1">
						<xsl:attribute name="fillcolor">#CAD3E4</xsl:attribute>
					</xsl:when>
				</xsl:choose> 
				
				<v:fill type="gradient" opacity="80%" color2="#eeeeee" angle="-90"/>
				<table style="table-layout:fixed"  >
				<tr>
					<td  style="width:25px;padding:6px">
						<xsl:element name="img">
							<xsl:choose>
								<xsl:when test="position()=1">
									<xsl:attribute name="src">/images/workflow/initstep.gif</xsl:attribute>
								</xsl:when>
								<xsl:when test="position()=last()">
									<xsl:attribute name="src">/images/workflow/endstep.gif</xsl:attribute>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<xsl:when test="./Attributes/StepType=1">
											<xsl:attribute name="src">/images/workflow/sp.gif</xsl:attribute>
										</xsl:when>
										<xsl:otherwise>
											<xsl:attribute name="src">/images/workflow/hq.gif</xsl:attribute>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:element>
					
					</td>
					<td style="width:70px">
						<b><xsl:value-of select="./Attributes/StepID" /></b><xsl:text disable-output-escaping="yes"> </xsl:text><xsl:value-of select="./Attributes/StepName"/>
					</td>
					<td style="width:40px">
						<xsl:value-of select="./Attributes/StepStatusName"/>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<hr/>
					</td>
				</tr>
				<xsl:call-template name="StepMember" />
				</table>
		</xsl:element>
		</xsl:element>
	</xsl:template>


	<xsl:template name="StepMember">
    <xsl:choose>
      <xsl:when test ="/Process/@IsEntity = 1">
      </xsl:when>
      <xsl:otherwise>
        <xsl:for-each select="./Bands/Band">
          <tr>
              <td width="18px"><img src="/images/workflow/member.gif" /></td>
              <td><xsl:value-of select="./BandName"/></td>
              <td width="40px"><xsl:value-of select="./NodeStatus"/></td>
          </tr>
        </xsl:for-each>        
      </xsl:otherwise>
    </xsl:choose>
	</xsl:template>


  <xsl:template name="CreateLine">
    <xsl:for-each select="./Steps/Step">
      <xsl:variable name="stepid" select="./Attributes/StepID" />

      <xsl:variable name="heightpos" select = "$stepid * 10 + 30" />
      
      <xsl:for-each select="./Relations/Relation">
          <xsl:variable name="nextstepid" select="./NextStepID" />

            
            <xsl:choose>
				<xsl:when test="$nextstepid > $stepid + 1 ">
			
					<xsl:variable name="endpos" select = "($nextstepid - $stepid) * 190 - 125" />
					<xsl:variable name="bgnpos" select = "$stepid * 190 - 55" />
		            
					<xsl:element name="div">
					<xsl:attribute name="style">z-index:100;position:absolute;top:<xsl:value-of  select="30 - ($stepid * 10)" /></xsl:attribute>
					<xsl:element name="v:polyline">
						<xsl:attribute name="filled">false</xsl:attribute>
						<xsl:attribute name="Points">0,-10 0,-<xsl:value-of  select="string($heightpos)" /><xsl:text disable-output-escaping ="yes"> </xsl:text><xsl:value-of  select="string($endpos)" />,-<xsl:value-of  select="string($heightpos)" /><xsl:text disable-output-escaping ="yes"> </xsl:text><xsl:value-of  select="string($endpos)" />,-10</xsl:attribute>
						<xsl:attribute name="style">position:relative;left:<xsl:value-of  select="string($bgnpos)" /></xsl:attribute>
						<xsl:call-template name="CreateStroke" ><xsl:with-param name="StrokeType" >F</xsl:with-param></xsl:call-template>
					</xsl:element>
					</xsl:element>
				</xsl:when>
				
				<xsl:when test="$nextstepid &lt; $stepid + 1 ">
					<xsl:variable name="endpos" select = "($stepid - $nextstepid) * 190 + 120" />
					<xsl:variable name="bgnpos" select = "$nextstepid * 190 - 180" />
			        
					<xsl:element name="div">
						<xsl:attribute name="style">z-index:100;position:absolute;top:<xsl:value-of  select="30 - ($stepid * 10)" /></xsl:attribute>
						<xsl:element name="v:polyline">
						<xsl:attribute name="filled">false</xsl:attribute>
						<xsl:attribute name="Points">0,-10 0,-<xsl:value-of  select="string($heightpos)" /><xsl:text disable-output-escaping ="yes"> </xsl:text><xsl:value-of  select="string($endpos)" />,-<xsl:value-of  select="string($heightpos)" /><xsl:text disable-output-escaping ="yes"> </xsl:text><xsl:value-of  select="string($endpos)" />,-10</xsl:attribute>
						<xsl:attribute name="style">position:relative;left:<xsl:value-of  select="string($bgnpos)" /></xsl:attribute>
						<xsl:call-template name="CreateStroke" ><xsl:with-param name="StrokeType" >P</xsl:with-param></xsl:call-template>
						</xsl:element>
					</xsl:element>				
				</xsl:when>
				
				<xsl:otherwise>

					<xsl:variable name="bgnpos" select = "$nextstepid * 190 - 226" />
				    
					<xsl:element name="div">
						<xsl:attribute name="style">z-index:100;position:absolute;top:50px</xsl:attribute>
						<xsl:element name="v:line">
							<xsl:attribute name="from">0,0</xsl:attribute>
							<xsl:attribute name="to">30,0</xsl:attribute>
							<xsl:attribute name="style">position:relative;left:<xsl:value-of  select="string($bgnpos)" /></xsl:attribute>
							<xsl:call-template name="CreateStroke" ><xsl:with-param name="StrokeType" >F</xsl:with-param></xsl:call-template>
						</xsl:element>
					</xsl:element>			

				</xsl:otherwise>
				
		</xsl:choose>
        
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
  
  
	<xsl:template name="CreateArrow">
    <v:line style="position:relative" from="0,0" to="30,0" color="#ffffff">
      <v:stroke Color="#ffffff"/>
    </v:line>
	</xsl:template>
	
	<xsl:template name="CreateStroke">
		<xsl:param name="StrokeType" />
		<xsl:element name="v:stroke">
			<xsl:choose>
				<xsl:when test="$StrokeType='F'">
					<xsl:attribute name="EndArrow">Classic</xsl:attribute>		
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="StartArrow">Classic</xsl:attribute>		
				</xsl:otherwise>
			</xsl:choose>
			
			<xsl:choose>
				<xsl:when test="./NextStepID/@IsChoose = 1">
					<xsl:attribute name="Color">#F79A01</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="Color">#cccccc</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:element>
	</xsl:template>
	
	<xsl:attribute-set name="steprect">
		<xsl:attribute name="arcsize">5%</xsl:attribute>	
		<xsl:attribute name="fillcolor">#dddddd</xsl:attribute>
		<xsl:attribute name="strokecolor">#9B9B9B</xsl:attribute>
		<xsl:attribute name="strokeweight">1px</xsl:attribute>	
		<xsl:attribute name="style">width:100%;text-align:left;height:100%;</xsl:attribute>	
	</xsl:attribute-set>
</xsl:stylesheet>